;**************************************************************************** 
;Copyright © 2008-2011 Oregon State University                                
;All Rights Reserved.                                                         
;                                                                             
;                                                                             
;Permission to use, copy, modify, and distribute this software and its        
;documentation for educational, research and non-profit purposes, without     
;fee, and without a written agreement is hereby granted, provided that the    
;above copyright notice, this paragraph and the following three paragraphs    
;appear in all copies.                                                        
;                                                                             
;                                                                             
;Permission to incorporate this software into commercial products may be      
;obtained by contacting Oregon State University Office of Technology Transfer.
;                                                                             
;                                                                             
;This software program and documentation are copyrighted by Oregon State      
;University. The software program and documentation are supplied "as is",     
;without any accompanying services from Oregon State University. OSU does not 
;warrant that the operation of the program will be uninterrupted or           
;error-free. The end-user understands that the program was developed for      
;research purposes and is advised not to rely exclusively on the program for  
;any reason.                                                                  
;                                                                             
;                                                                             
;IN NO EVENT SHALL OREGON STATE UNIVERSITY BE LIABLE TO ANY PARTY FOR DIRECT, 
;INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST      
;PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 
;IF OREGON STATE UNIVERSITYHAS BEEN ADVISED OF THE POSSIBILITY OF SUCH        
;DAMAGE. OREGON STATE UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,       
;INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
;FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY OF               
;NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,    
;AND OREGON STATE UNIVERSITY HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,       
;SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                            
;                                                                             
;**************************************************************************** 

function compare_angles, xcoords, ycoords, yrange

    ;need three points.  compares the angles between
    ;  pt 1 to pt2 vs pt 1 to pt 3, but only if they're
    ;  the same sign (i.e. only if both recovery or disturbance)

    if n_elements(xcoords) ne 3 or n_elements(ycoords) ne 3 then return, -1
    
    ;get the slope of the prior to current points
    ydiff2 = (ycoords[2]-ycoords[1])
    ydiff1 = (ycoords[1]-ycoords[0])
    ;ydiff3 = (ycoords[2]-ycoords[0])	;first to last
    
    angle1 = atan(float(ydiff1)/(xcoords[1]-xcoords[0]))
    angle2 = atan(float(ydiff2)/(xcoords[2]-xcoords[1]))
    ; angle3 = atan(float(ydiff3)/(xcoords[2]-xcoords[0]))
    
    ;compare 'em
    mx = max([angle1, angle2], min=mn)
    
    diff = (mx-mn)* !radeg
    
    return, diff
end
